package main

import (
	"context"
	"flag"
	"fmt"
	"github.com/zeromicro/go-zero/core/conf"
	"github.com/zeromicro/go-zero/core/discov"
	"github.com/zeromicro/go-zero/zrpc"
	"modbus/rpcclient/config"
	"modbus/rpcclient/svc"
	"modbus/rpcclient/types/iotrpc"
	"time"
)

var configFile = flag.String("f", "etc/rpc.yaml", "the config file")

func main() {
	flag.Parse()
	var c config.Config
	conf.MustLoad(*configFile, &c)
	cont := svc.NewClientContext(c)
	clientConf := zrpc.RpcClientConf{Etcd: discov.EtcdConf{Hosts: cont.Config.Etcd.Hosts, Key: cont.Config.Etcd.Key}}
	//clientConf := zrpc.RpcClientConf{Target: "127.0.0.1:8080"}
	client := zrpc.MustNewClient(clientConf)
	conn := client.Conn()
	tableClient := iotrpc.NewDeviceTableClient(conn)
	for {
		time.Sleep(time.Second)
		list, err := tableClient.GetDeviceTableList(context.Background(), nil)
		if err != nil {
			fmt.Println(err)
		}
		fmt.Println(list)
	}
}
